package com.wuzheng.wisgo.sanitation.cloud.repository.mapper.tbox;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.wuzheng.wisgo.sanitation.cloud.repository.builder.tbox.SelectVehCodeToReceiveInfoBuilder;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.tbox.ReceiveInfo;
import com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoSelectAllDto;
import com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoSelectStopTimeDto;
import com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoSelectVehDto;
import com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoToVehicleVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * T-Box数据接受表(所有数据) Mapper 接口
 * </p>
 *
 * @author sp
 * @since 2019-10-10
 */
public interface ReceiveInfoMapper extends BaseMapper<ReceiveInfo> {

    /*
     * @MethodName: selectVehCodeFromVehicle
     * @Description: 轨迹回放检索框信息查询——车牌号查询
     * @Param: [vehCode]
     * @Return: java.util.List<com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoToVehicleVo>
     * @Author: sunpeng
     * @Date: 2019/10/10
    **/
    @SelectProvider(type = SelectVehCodeToReceiveInfoBuilder.class, method = "builderSelectVehCodePListSql")
    List<ReceiveInfoToVehicleVo> selectVehCodeFromVehicle(@Param("vehCode") String vehCode,@Param("customerId") String customerId);


    /*
     * @MethodName: selectByVehInfo
     * @Description: 轨迹回放--详情列表数据查询(车牌号，车速等等)
     * @Param: [map]
     * @Return: java.util.List<com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoSelectVehDto>
     * @Author: sunpeng
     * @Date: 2019/10/14
    **/
    List<ReceiveInfoSelectVehDto> selectByVehInfo(Map<String, Object> map);

    /*
     * @MethodName: selectByCount
     * @Description: TODO
     * @Param: [map]
     * @Return: java.util.List<com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoSelectVehDto>
     * @Author: sunpeng
     * @Date: 2019/10/29
    **/
    Integer selectByCount(Map<String, Object> map);

    /*
     * @MethodName: selectByReveiceInfo
     * @Description: 轨迹回放查询所有经纬度点(包含停留点)
     * @Param: [customerId, tMapType, vehCode, startTime, stopTime]
     * @Return: java.util.List<com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoSelectAllDto>
     * @Author: sunpeng
     * @Date: 2019/10/15
    **/
    @Select("SELECT DISTINCT tri.id,ba_vehicle.veh_code,ba_vehicle.veh_vin_code AS recVin,tri.rec_collection_time,tri.rec_vin,tri.rec_job_status,tri.rec_veh_status,tri.rec_vch_direction,tri.rec_veh_speed,tri.rec_longitude,tri.rec_latitude,tmb.t_tran_longitude,tmb.t_tran_latitude\n" +
            "FROM t_receive_info tri " +
            "LEFT JOIN t_map_base tmb ON  tri.rec_longitude=tmb.t_longitude AND tri.rec_latitude=tmb.t_latitude " +
            "LEFT JOIN ba_vehicle ON tri.veh_id=ba_vehicle.id\n" +
            "WHERE tri.customer_id=#{customerId} AND tmb.t_map_type=#{tMapType} AND ba_vehicle.veh_code=#{vehCode} AND tri.rec_collection_time>#{startTime} AND tri.rec_collection_time<=#{stopTime}")
    List<ReceiveInfoSelectAllDto> selectByLongLatInfo(@Param("customerId") String customerId, @Param("tMapType") String tMapType, @Param("vehCode") String vehCode,
                                                      @Param("startTime") Timestamp startTime, @Param("stopTime") Timestamp stopTime);

    /*
     * @MethodName: selectStopLongLatFromStopTime
     * @Description: 轨迹回放--停留点
     * @Param: [customerId, tMapType, vehCode, startTime, stopTime]
     * @Return: java.util.List<com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoSelectStopTimeDto>
     * @Author: sunpeng
     * @Date: 2019/10/16
    **/
    @Select("SELECT DISTINCT tst.id, tst.t_stop_data,tst.t_stop_time,tst.t_end_stop_time,tmb.t_address,bv.veh_code,bv.veh_vin_code," +
            "tst.t_longitude,tst.t_latitude\n" +
            "FROM t_stop_time tst\n" +
            "LEFT JOIN t_map_base tmb ON tst.t_longitude=tmb.t_longitude AND tst.t_latitude=tmb.t_latitude LEFT JOIN ba_vehicle bv ON tst.veh_id=bv.ID\n" +
            "WHERE tst.de_flag=FALSE AND tst.customer_id=#{customerId} AND tmb.t_map_type=#{tMapType} AND bv.veh_code=#{vehCode} AND tst.create_time>#{startTime} AND tst.create_time<=#{stopTime} ")
    List<ReceiveInfoSelectStopTimeDto> selectStopLongLatFromStopTime(@Param("customerId") String customerId, @Param("tMapType") String tMapType,@Param("vehCode") String vehCode,
                                                                     @Param("startTime") Timestamp startTime, @Param("stopTime") Timestamp stopTime);


    /*
     * @MethodName: selectByReveiceInfo
     * @Description: 轨迹回放查询所有经纬度点(包含停留点)
     * @Param: [customerId, tMapType, vehCode, startTime, stopTime]
     * @Return: java.util.List<com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoSelectAllDto>
     * @Author: sunpeng
     * @Date: 2019/10/15
     **/
    @Select("SELECT DISTINCT tri.id,tri.rec_longitude,tri.rec_latitude " +
            "FROM t_receive_info tri " +
            "WHERE tri.veh_id=#{vehId}")
    List<ReceiveInfo> selectByVehId(@Param("vehId") String vehId);

}
